//商品入库登记的全局变量
var shangpinrkdj = {
	url: {
	 getGongyingshangListURL:function(){
			return path + '/zidian/getGongyingshangList';
		},baocunShangpinrkdURL:function(){
			return path + '/shangpinrkd/baocunShangpinrkd';
		},addShangpinrkdmxURL:function(){
			return path + '/shangpinrkd/addShangpinrkdmx';
		},rukuURL:function(){
			return path + '/shangpinrkd/ruku';
		},getShangpinrkdxmxURL:function(){
			return path + '/shangpinrkd/getShangpinrkdmx';
		},shanchumxURL:function(){
			return path + '/shangpinrkd/shanchumx';
		},getShangpinCountURL:function(){
			return path + '/shangpinrkd/getShangpinCount';
		},getShangpinCountURL:function(){
			return path + '/shangpinrkd/getShangpinCount';
		}
	},
	init: function(firstDate,secondDate){
		common_util.dateTimePickerOne($('#begin-date'));
		common_util.dateTimePickerOne($('#ruku-date'));
		shangpinrkdj.myDateForRuku($('#list-date'));
		shangpinrkdj.bandFunction();
	},
	getinsertMsg: function(){
		
	},
	getmsg: function(){
		
	},
	find: function(){
		
	},
	//绑定的方法
	bandFunction: function(){
		var A = 0;
		$("#dhyaopin").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".nav-comsumer-goods").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		        	window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".shangpinrk").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".yaopin-pici").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".haocai-pici").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".kuc").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".rukugl").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		
		//下拉
		$(document).on('click','.gysul li',function(){
			var $val = $(this).attr('index');
			var str=$val.split(",");
			$('#gongyingsmc').val(str[0]);
			$('#gongyingsdz').val(str[1]);
			$('#gongyingsid').val(str[2]);
			$(this).parent('.gysul').css('display','none');
		});
		//供应商名称检索
		$(document).on('input', '#gongyingsmc', function () {
			shangpinrkdj.getGongyzdingshang();
		});
		//新建供应商
		$(document).on('click','#btnShangpinrkdAdd',function () {
			//$('#btnShangpinrkdAdd').attr('disabled', true);
			if($('#kaidan-date').val() == ''){
				notifyWarning("开单日期不能为空");
				$('#kaidan-date').addClass("n-invalid");
				return false;
			}
			
			if($('#rukurq').val() == ''){
				notifyWarning("入库日期不能为空");
				$('#rukurq').addClass("n-invalid");
				return false;
			}
			if($('#gongyingsmc').val() == ''){
				notifyWarning("供应商名称不能为空");
				$('#gongyingsmc').addClass("n-invalid");
				return false;
			}
			if($('#gongyingsmc').val().length > 100){
				notifyWarning("供应商名称长度不能超过100个字符");
				$('#gongyingsmc').addClass("n-invalid");
				return false;
			}
			if($('#fahuodh').val().length > 30){
				notifyWarning("发货单号长度不能超过30个字符");
				$('#fahuodh').addClass("n-invalid");
				return false;
			}
			if($('#beizhu').val().length > 512){
				notifyWarning("备注长度不能超过512个字符");
				$('#beizhu').addClass("n-invalid");
				return false;
			}
			var shangpinrkdid=$('#shangpinrkdid').val();
			console.log($('#formSave'));
			$.ajax({
				url: shangpinrkdj.url.baocunShangpinrkdURL(),
				type: 'post',
				data: $('#formSave').serialize(),
				success: function(result) {
				//判断是否请求成功
				if(result.succsess == true){
					notifySuccess('入库单保存成功');
						if(result.data!=''){
							 var str=result.data.split(",");
								$('#shangpinrkdid').val(str[0]);
								$('#gongyingsid').val(str[1]);
								$('#shangpinrkdmxid').val(str[0]);
							$('#shangpinrkdmxDiv').show();
							$('.wushuju-img').hide();
							 var sjc =new Date().getTime();
							 $('#btnruku').show();
							 $('.yaopinmc').focus();
						}
					}else { 
						notifyWarning('入库单保存失败');
					}
				}
			});
		});
		//返回
		$(document).on('click','#fanhui',function () {
			window.location.href = path+ "/views/kucun/rukugl/rukugl.jsp";
		});
		// 输入商品名称
		$(document).on('input','#yaopinmc',function() {
			getZdYaopinAndHaocai(this,0);
			if($(this).val()==""){
				$(this).siblings('ul').text('');
			}else{
				$(this).parent().parent().next(".rukusp-fujiaxx").css("display","table-row");
			}
		});
		//供应商名称下拉blur事件
		var gongyingshang = true;
		$('#gongyingsmc').blur(function(){
			$(this).parent().find('li').each(function(){
				if($(this).hasClass('hello')) {
					gongyingshang = false;
				}
				if($(this).text() == $('#gongyingsmc').val() ) {
					gongyingshang = false;
				}
			});
			if(gongyingshang) { 
				var gongyingsmc = $(this).parent().find('.hello');
				var val = $(this).val();
				if(gongyingsmc.length < 1) {
					if(val!=''&&gongyingshang) {
						$(this).focus();
						notifyWarning('请从诊所库存或者平台病库中选择供应商！');
					}
				}
				$(this).parent().parent().find('#gongyingsmc').val("");
				$(this).parent().find("#gongyingsmcul").html("");
			}
			gongyingshang = true;
		});
		// 商品下拉点击事件
		$(document).on("click",".shangpinmcul li.xuanzeli",function(){
			$(this).parent().parent().parent().find(".sy-td-warning").css("display","none");
			$(this).parent().parent().parent().find(".sy-td-danger").css("display","none");
			var id = $(this).attr('index');
			var iszs = $(this).attr('iszs');
			var leixing = $(this).attr('leixing');
			var uuid = $(this).attr('uuid');
			var yaopinlx = $(this).attr('yaopinlx');
			//$('#yaopinmc').val($(this).text())
			shangpinrkdj.shangpinrk(id,iszs,leixing,uuid,yaopinlx,$(this));	
		});
		//检测必须从平台或者诊所库中选择
		$(document).on('blur','[name="shangpinmc"]',function(){
			var val = $(this).val();
			var zsShangpinid = $(this).parent().parent().find('[name="zsShangpinid"]').val();
			var ptShangpinid = $(this).parent().parent().find('[name="ptShangpinid"]').val();
			var ptuuid = $(this).parent().parent().find('[name="ptuuid"]').val();
			var leixing = $(this).parent().parent().find('[name="leixing"]').val();
			jianceShangpin(val,zsShangpinid,ptShangpinid,ptuuid,leixing,this);
		});
		function jianceShangpin(val,zsShangpinid,ptShangpinid,ptuuid,leixing,obj){
			var yaopinmcli = $(obj).parent().find('.hello');
			if(yaopinmcli.length < 1) {
				if(val!=''&&zsShangpinid==''&&ptShangpinid=='') {
					if(!$(obj).parent().find(".dropdown-menu li").hasClass("hello")){
						$(obj).focus();
						notifyWarning('请从诊所库存或者平台药库中选择商品！');
						xuanzeypFlag = false;
					}else{
						xuanzeypFlag = true;
					}
				}
				if(val!=''&&zsShangpinid!=''&&zsShangpinid!='null') {
					var shangpin;
					if(leixing==0) {//药品
						shangpin = getYaopinById(zsShangpinid,0);
					}else{//耗材
						shangpin = getHaocaixq(zsShangpinid,0);
					}
					if(shangpin.bieming!=null&&shangpin.bieming!='') {
						if(val!=shangpin.bieming) {
							$(obj).focus();
							notifyWarning('请从诊所库存或者平台药库中选择药品！');
							xuanzeypFlag = false;
						}
					}else{
						if(val!=shangpin.mingcheng) {
							$(obj).focus();
							notifyWarning('请从诊所库存或者平台药库中选择药品！');
							xuanzeypFlag = false;
						}else{
							xuanzeypFlag = true;
						}
					}
				}
				if(val!=''&&ptuuid!=''&&ptuuid!='null'&&ptuuid!='undefined'&&ptuuid!=undefined) {
					var shangpin;
					if(leixing==0) {//药品
						shangpin = getYaopinById(ptuuid,1);
					}else{//耗材
						shangpin = getHaocaixq(ptuuid,1);
					}
					if(val!=shangpin.mingcheng) {
						$(obj).focus();
						notifyWarning('请从诊所库存或者平台药库中选择药品！');
						xuanzeypFlag = false;
					}else{
						xuanzeypFlag = true;
					}
				}
				
			}
		}
		$(document).on('click',"#btnaddShangpinrkdmx",function(){
			if($('#yaopinmc').val() == ''){
				notifyWarning("商品名称不能为空");
				$('#yaopinmc').focus();
				return false;
			}else if($('#yaopinmc').val().length > 30){
				notifyWarning("商品名称长度不能超过30个字符");
				$('#yaopinmc').focus();
				return false;
			}else if($('#jinhuoj').val() == ''){
				notifyWarning("进货价不能为空");
				$('#jinhuoj').focus();
				return false;
			}else if($('#jinhuoj').val().length > 20){
				notifyWarning("进货价长度不能超过20个字符");
				$('#jinhuoj').focus();
				return false;
			}else if($('#chufangj').val() == ''){
				notifyWarning("处方价不能为空");
				$('#chufangj').focus();
				return false;
			}else if($('#chufangj').val().length > 20){
				notifyWarning("处方价长度不能超过20个字符");
				$('#jinhuoj').focus();
				return false;
			}else if($('#shuliang').val() == ''){
				notifyWarning("数量不能为空");
				$('#shuliang').focus();
				return false;
			}else if($('#shuliang').val().length > 10){
				notifyWarning("数量长度不能超过10个字符");
				$('#shuliang').focus();
				return false;
			}else if($('#shangpinph').val().length > 16){
				notifyWarning("商品批号长度不能超过16个字符");
				$('#shangpinph').focus();
				return false;
			}else if($('#youxiaojzrq').val() == ''){
				notifyWarning("有效期不能为空");
				$('#youxiaojzrq').focus();
				return false;
			}else if($('.sy-td-danger').css('display') == 'block'){
				notifyWarning("请进入库存模块，维护商品基本信息");
				return false;
			}else{
				shangpinrkdj.baocunShangpinrkdmx();
				$('.yaopinmc').focus();
			}
		});
		
		//重置
		$(document).on('click','#btnChongZhi',function(){
			$('#mxformSave')[0].reset();
			$('#shangpinlx').text('');
			$('#shangpinjx').text('');
			$('#shangpinbzgg').text('');
			$('#shangpinsccj').text('');
			$('.sy-td-warning').hide();
			$('.sy-td-danger').hide();
			$('.chufangdw').text('');
			$('.danhedw').text('');
			$('.yaopinmc').focus();
		})
		// 删除明细
		$(document).on("click", "table .a-shanchu", function(){
			var id = $(this).attr('id');
			var shangpinrkdid=$('#shangpinrkdid').val();
			shangpinrkdj.shanchumx(id, shangpinrkdid);
			
		});
		//点击入库按钮
		$(document).on('click',"#btnruku",function(){
			if($('#xsShangpinrkdmxtab tr').text() == ''){
				notifyWarning("入库明细为空，请添加");
				return false;
			}else{
				if($('#fahuodh').val() != ''){
					$('#dialog-fahuodh').text($('#fahuodh').val());
				}else{
					$('#dialog-fahuodh').text('（未填写）').css('color','#777');
				}
				$('#dialog-rukurq').text($('#rukurq').val());
				$('#dialog-gys').text($('#gongyingsmc').val());
				$('#dialog-pls').text($('#pinleislsp').text());
				$('#dialog-jinhj').text($('#jinsuozjsp').text());
				$('#dialog-xiaosj').text($('#chufangzjsp').text());
				$('#dialog-ruku').modal();
			}
		});
		//点击入库确认弹窗
		$(document).on('click',"#dialog-queding",function(){
			$(this).attr('disabled', true);
			$('#dialog-ruku').modal('hide');
			 var shangpinrkdid=$('#shangpinrkdid').val();
			shangpinrkdj.shangpinrkdrk(shangpinrkdid);
		});
		//table 下input触发blur校验
		$(document).on('blur','#yaopinmc',function(){
			if($(this).val().length > 30){
				notifyWarning("商品名称长度不能超过30个字符");
				return false;
			}
		})
		$(document).on('blur','#jinhuoj',function(){
			var val = $(this).val();
			var jinhuojia = true;
			if(val != ''){
				var patrn = /^\d+(\.\d+)?$/;
				if(!patrn.test(val)){
					notifyWarning('请输入进货价');
					$(this).focus();
					jinhuojia = false;
				}
			}
			if($(this).val().length > 20){
				notifyWarning("进货价长度不能超过20个字符");
				return false;
			}
		})
		$(document).on('blur','#chufangj',function(){
			var val = $(this).val();
			var chufangjia = true;
			if(val != ''){
				var patrn = /^\d+(\.\d+)?$/;
				if(!patrn.test(val)){
					notifyWarning('请输入处方价');
					$(this).focus();
					chufangjia = false;
				}
			}
			if($(this).val().length > 20){
				notifyWarning("处方价长度不能超过20个字符");
				return false;
			}
		})
		$(document).on('blur','#shuliang',function(){
			var val = $(this).val();
			var chufangjia = true;
			if(val != ''){
				var patrn = /^\d+(\.\d+)?$/;
				if(!patrn.test(val)){
					notifyWarning('请输入数量');
					$(this).focus();
					chufangjia = false;
				}
			}
			if($(this).val().length > 10){
				notifyWarning("数量长度不能超过10个字符");
				return false;
			}
		})
		$(document).on('blur','#shangpinph',function(){
			if($(this).val().length > 16){
				notifyWarning("商品批号长度不能超过16个字符");
				return false;
			}
		})
		
		//精确查找
		$(document).off('click', '#jingqueczsp');
		$(document).on('click','#jingqueczsp',function(){
			var mingcchen = $(this).parent().parent().find("#yaopinmc").val();
			$(this).parent().parent().find("#yaopinmc").val('').addClass('qiaojie shangpinrk');
			$(this).parent().parent().find(".sy-td-warning").css('display','none');
			$(this).parent().parent().find(".sy-td-danger").css('display','none');
			$(this).parent().parent().parent().find(".ruku-jinhuojia").val('');
			$(this).parent().parent().parent().find(".danhedw").text('');
			$(this).parent().parent().parent().find(".ruku-xiaoshoujia").val('');
			$(this).parent().parent().parent().find(".chufangdw").text('');
			$(this).parent().parent().parent().find(".ruku-shuliang").val('');
			$(this).parent().parent().parent().find(".rukusp-deadtime").val('');
			$(this).parent('ul').html('').css('display','none');
			$('.modal-seh-leixing').css('display','block');
			$('.modal-seh-laiyuan').css('display','block');
			$('.btn-jingquecz-check').css('display','block');
			$('.check').removeClass("check2").addClass("check1");
			$("#shangpinjqcz").modal();
			$('#shangpinmc').val(mingcchen);
			$('#shengchancj').val('');
			$('#gongyings').val('');
			$('#shangpinjqcz .modal-content').css({'top':'150px','left':'-55px'});
			showJingq();
		});
		//进货价
		$(document).on("focusout",".ruku-jinhuojia",function(){
			var jinhuojia = $(this).val();
			var xiaoshoujia = $(this).parent().parent().find(".ruku-xiaoshoujia").val();
			var chailingbz =  $(this).parent().parent().find(".chailingbz").val();
			var chailingsl =  $(this).parent().parent().find(".chailingsl").val();
		 	if( jinhuojia != "" && xiaoshoujia != ""&&chailingbz == 1 ){
		 		var gaodi =(xiaoshoujia*chailingsl)-jinhuojia;
		 		if(gaodi<0){
		 			notifyInfo('处方价低于进货价（处方价=处方金额*拆零数量）');
		 		}
			}
		 	if( jinhuojia != "" && xiaoshoujia != ""&&chailingbz != 1 ){
				var gaodi =xiaoshoujia-jinhuojia;
				if(gaodi<0){
					notifyInfo('处方价低于进货价');
				}
			}
		});
		   
		  //处方价
		$(document).on("focusout",".ruku-xiaoshoujia",function(){
			var xiaoshoujia = $(this).val();
			var jinhuojia = $(this).parent().parent().find(".ruku-jinhuojia").val();
			var chailingbz =  $(this).parent().parent().find(".chailingbz").val();
			var chailingsl =  $(this).parent().parent().find(".chailingsl").val();
			if( jinhuojia != "" && xiaoshoujia != ""&&chailingbz == 1 ){
		   		var gaodi =(xiaoshoujia*chailingsl)-jinhuojia;
		   		if(gaodi<0){
		   			notifyInfo('处方价低于进货价（处方价=处方金额*拆零数量）');
		   		}
		   	 }
		   	 if(jinhuojia != "" && xiaoshoujia != ""&&chailingbz != 1 ){
		  		 var gaodi =xiaoshoujia-jinhuojia;
		  		 if(gaodi<0){
		  			 notifyInfo('处方价低于进货价');
		  		 }
		  	  }
		 });
		$(document).on("mouseover",".sy-td-warning .fa",function() {
		    $(this).parent().popover('show');
		});
		$(document).on("mouseout",".sy-td-warning .fa",function() {
		    $(this).parent().popover('hide');
		});
		$(document).on("mouseover",".sy-td-danger .fa",function() {
		    $(this).parent().popover('show');
		});
		$(document).on("mouseout",".sy-td-danger .fa",function() {
		    $(this).parent().popover('hide');
		});
		$(document).on('input','.yaopinmc',function(){
			if($(this).val() == ''){
				$('.shangpinmcul').html('');
				$('.sy-td-warning').hide();
				$('.sy-td-danger').hide();
				$('.danhedw').text('');
				$('.chufangdw').text('');
				$('#shangpinlx').text('(未设置)').css('color','#777');
				$('#shangpinjx').text('(未设置)').css('color','#777');
				$('#shangpinbzgg').text('(未设置)').css('color','#777');
				$('#shangpinsccj').text('(未设置)').css('color','#777');
			}
		})
	},getGongyzdingshang(){//检索字典供应商
		var val = $('#gongyingsmc').val();
		if(val!=''){
			$.ajax({
				url: shangpinrkdj.url.getGongyingshangListURL(),
				type:'post',
				data:{"strParams":val},
				success:function(data) {
					var str = "";
					if(data != '') {
						var IszsMark1 = 0;
						var IszsMark2 = 0;
						$(data).each(function(){
							if(this.iszs==0) {
								if(IszsMark1==0) {
									str+= '<span>当前在库供应商</span>';
									IszsMark1++;
								}
							}
							if(this.iszs==1) {
								if(IszsMark2==0) {
									str+= '<span class="comm-dropm-span">以下供应商品均不在您的系统中</span>';
									IszsMark2++;
								}
							}
							str+='<li index="'+this.mingcheng+','+this.dizhi+','+this.id+'">'+this.mingcheng+'</li>';
						});
					} 
					$('#gongyingsmcul').html("");
					$('#gongyingsmcul').html(str);
				}
			});
		}
	},
	//下拉商品后获取明细的一些属性
	shangpinrk(preid,preiszs,preleixing,preuuid,preyaopinlx,pre$this){
		var dbshijian2;
		xuanzeypFlag = true;
		var id = preid ;
		var iszs = preiszs;
		var leixing = preleixing;
		var uuid = preuuid;
		var yaopinlx = preyaopinlx;
		var obj;
		if ($('.qiaojie').hasClass('qiaojie')) {
			var strli = "<li style='display:none' class='world xuanzeli'>1111</li>";
			$('.qiaojie').siblings('.zidiancxul').append(strli);
			var $this = $('.qiaojie').siblings('.zidiancxul').find('.world');
		} else {
			var $this = pre$this;
		}
		if(!dbshijian2){
			
			$.ajax({
				type:"post",
				url:path+"/base/getShujukuTime",
				async:false,
				success: function(data){
					dbshijian2=data.dbCurrentDate;
				}
			});
			
		}
		getShujukuTime(dbshijian2);
		var yearNow = dbshijian2.substring(0,4);
		var yearAfter2 = Number(yearNow)+2;
		var dbshijianAfter =  dbshijian2.replace(yearNow,yearAfter2);
		if(leixing == 0) {//药品
			if(iszs==0) {
				obj = getYaopinById(id,iszs);
			}else{
				obj = getYaopinById(uuid,iszs);
			}
		}else if(leixing == 1){//耗材
			if(iszs==0) {
				obj = getHaocaixq(id,iszs);
			}else{
				obj = getHaocaixq(uuid,iszs);
			}
		}
		chailingsl = obj.chailingsl;
		chailingbz = obj.chailingbz;
		var flag;
		$this.parent().parent().parent().parent().find('[name="zsShangpinid"]').each(function(){
			if(!$(this).hasClass('notComprareThis')) {//当前行不比较
				if(iszs==0 && obj.id==$(this).val()){
					notifyWarning('请不要添加重复药品');
					flag = true;
					return false;
				}
			}
		});
		$('[name="zsShangpinid"]').each(function(){
			if(iszs==0 && obj.id==$(this).val()){
				notifyWarning('请不要添加重复药品');
				flag = true;
				return false;
			}
		})
		$this.parent().parent().parent().parent().find('[name="ptShangpinid"]').each(function(){
			if(!$(this).hasClass('notComprareThis')) {
				if(iszs==1&&obj.id==$(this).val()) {
					notifyWarning('请不要添加重复药品');
					flag = true;
					return false;
				}
			}
		});
		
		$this.parent().parent().parent().removeClass('notComprareThis');
		if(flag) {
			$(".f-input-li").css("display","none");
			$this.parent().parent().parent().find('input:text,input:hidden').val('').removeClass("n-invalid");
			$this.parent().parent().parent().find(".sy-td-warning").css("display","none");
			$this.parent().parent().parent().find(".sy-td-danger").css("display","none");
			return false;
		}
		if(iszs==0) {
			$this.parent().parent().parent().find('[name="zsShangpinid"]').val(id);
			$this.parent().parent().parent().find('[name="ptShangpinid"]').val('');
			$this.parent().parent().parent().find('[name="chailingbz"]').val(obj.chailingbz);
			$this.parent().parent().parent().find('[name="chailingsl"]').val(obj.chailingsl);
			$this.parent().parent().find('.sy-td-warning').css('display','none');
		}else{
			$this.parent().parent().parent().find('[name="zsShangpinid"]').val('');
			$this.parent().parent().parent().find('[name="ptShangpinid"]').val(id);
			$this.parent().parent().parent().find('[name="ptuuid"]').val(uuid);
			$this.parent().parent().parent().find('[name="chailingbz"]').val(obj.chailingbz);
			$this.parent().parent().find('.sy-td-warning').css('display','block');
			$this.parent().parent().find('.sy-td-warning').attr('data-content','该商品不在您的诊所库存中');
		}
		
		
		if(obj.bieming!='null'&&obj.bieming!=''&&obj.bieming!=null) {
			$this.parent().parent().find('#yaopinmc').val(obj.bieming);
		}else{
			$this.parent().parent().find('#yaopinmc').val(obj.mingcheng);
		}
		if(yaopinlx==1) {
			$this.parents('tr').find('.rukusp-deadtime').val(dbshijianAfter);
		}
		var baozhuangdw = obj.baozhuangdw;
		if(baozhuangdw  == '' || baozhuangdw == 'null'){
			var baozhuangdw = '';
		}
		if(iszs==1&&yaopinlx==1){// 不在库饮片，默认单位为克
			$this.parent().parent().parent().find('.danhedw').text(baozhuangdw);
			$this.parent().parent().parent().find('.chufangdw').text(baozhuangdw);
			$this.parent().parent().parent().find('[name="danwei"]').val(baozhuangdw);
		}else{
			if(obj.chailingbz != null&&obj.chailingbz == 1){
				$this.parent().parent().parent().find('.chufangdw').text(obj.chailingdw);
			} else {
				$this.parent().parent().parent().find('.chufangdw').text(baozhuangdw);
			}
			$this.parent().parent().parent().find('.danhedw').text(baozhuangdw);
			$this.parent().parent().parent().find('[name="danwei"]').val(baozhuangdw);
			if(obj.baozhuangdw==null||obj.baozhuangdw==''||obj.baozhuangdw=='null') {
				$this.parent().parent().find('.sy-td-danger').css('display','block');
				$this.parent().parent().find('.sy-td-danger').attr('data-content','该商品不在库存并且缺少单位信息，请到【药品/耗材库存】中维护信息');
			}
		}
		$this.parent().parent().parent().find('[name="leixing"]').val(leixing);
		$this.parent().parent().parent().find('[name="tiaoxingma"]').val(obj.tiaoxingma);
		if(obj.jinhuojia!=null&&obj.jinhuojia!='') {
			$this.parent().parent().parent().find('[name="jinhuojia"]').val(obj.jinhuojia);
		}
		if(obj.xiaoshoujia!=null&&obj.xiaoshoujia!='') {
			$this.parent().parent().parent().find('[name="xiaoshoujia"]').val(obj.xiaoshoujia);
		}
		if(leixing == 0) {
			$this.parent().parent().parent().find('#shangpinlx').text(convertYaopinlx(yaopinlx));
		}else{
			$this.parent().parent().parent().find('#shangpinlx').text("耗材");
		}
		$this.parent().parent().parent().find('#shangpinbzgg').text(obj.baozhuanggg || '(未设置)').css('color','#777');
		$this.parent().parent().parent().find('#shangpinjx').text(obj.jixing || '(未设置)').css('color','#777');
		$this.parent().parent().parent().find('#shangpingys').text(obj.gongyingshang || '(未设置)').css('color','#777');
		$this.parent().parent().parent().find('#shangpinsccj').text(obj.shengchancj || '(未设置)').css('color','#777');
		$this.parent().parent().parent().next().css("display","table-row");
		$(".f-input-li").css("display","none");
		
		$this.parent().parent().parent().parent().find("input:visible:not('.wm-group')").each(function(){
			if($(this).val()==""){
				$(this).focus();
				return false;
			}
		});
		$this.parent().text('');
		$this.parent().hide();
	},//商品入库明细保存
	baocunShangpinrkdmx(){
		 var shangpinrkdid=$('#shangpinrkdid').val();
		 $('#shangpinrkdmxid').val(shangpinrkdid);
		$.ajax({
			url:shangpinrkdj.url.addShangpinrkdmxURL(),
			type:'post',
			data: $('#mxformSave').serialize(),
			success:function(result) {
				if(result.succsess == true){
					 notifySuccess("添加入库单明细成功");
					 var shangpinrkdid= $('#shangpinrkdid').val();
					 shangpinrkdj.getShangpinrkdxmx(shangpinrkdid);
					$('#mxformSave')[0].reset();
					$('#shangpinlx').text('');
					$('#shangpinjx').text('');
					$('#shangpinbzgg').text('');
					$('#shangpinsccj').text('');
					$('.sy-td-warning').hide();
					$('.sy-td-danger').hide();
					$('.chufangdw').text('');
					$('.danhedw').text('');
					shangpinrkdj.getShangpinCount(shangpinrkdid);
				}
			}
		});
		//商品入库单点击入库
	},shangpinrkdrk(shangpinrkdid){
		$.ajax({
			url:shangpinrkdj.url.rukuURL(),
			type:'post',
			data:{"shangpinrkdid":shangpinrkdid},
			success:function(result) {
				if(result.succsess == true){
					 notifySuccess("入库成功"); 
					 window.location.href = path+ "/views/kucun/rukugl/rukugl.jsp";
				}
			}
	   });
		//获取商品入库单明细
	},getShangpinrkdxmx(shangpinrkdid){
		$.ajax({
			url:shangpinrkdj.url.getShangpinrkdxmxURL(),
			type:'post',
			data:{"shangpinrkdid":shangpinrkdid},
			success:function(result) {
				console.log(result)
				if(result.succsess == true){
					$('#xsShangpinrkdmxtab').empty();
					  var str;
							$.each(result.data, function (key, val) {
								str += '<tr id="tr_'+val.shangpinrkdmxid+'">'
									 	+'<td width="3%">'+(key+1)+'</td>'
									 	+'<td width="18%" class="left">'+val.shangpinmc+'</td>'
									 	+'<td width="15%" class="right">'+val.jinhuojia+'元 / ' + val.danwei + '</td>';
									 	if(val.chailingbz == 0){
									 		str += '<td width="15%" class="right">'+val.xiaoshoujia+'元  / ' + val.danwei + '</td>';
									 	}else{
									 		str += '<td width="15%" class="right">'+val.xiaoshoujia+'元  / ' + val.chufangdw + '</td>';
									 	}
									 	str += '<td width="15%" class="right">'+val.shuliang+val.danwei+'</td>'
									 	+'<td width="8%">'+val.shangpinph+'</td>'
									 	+'<td width="10%">'+val.youxiaojzrq+'</td>'
									 	+'<td width="8%">'+val.shangpinlx+'</td>'
									 	+'<td width="8%">'+val.shangpinjx+'</td>'
									 	+'<td width="8%">'+val.baozhuanggg+'</td>' 
									 	+'<td width="18%" class="left">'+val.shengchancj+'</td>' 
					                    +'<td width="10%" style="overflow:inherit;"><span class="caozuo caozuo1 a-shanchu" id="'+val.shangpinrkdmxid+'">删除</span></td>'
					                    +'<input type="hidden" name="zsShangpinid" value="' + val.zsShangpinid + '">'
						                + '</tr>';
							});
							$('#xsShangpinrkdmxtab').append(str);
				 }
			}
	   });
	},
	//删除明细
	shanchumx(shangpinrkdmxid, shangpinrkdid){
		$.ajax({
			url:shangpinrkdj.url.shanchumxURL(),
			type:'post',
			data:{"shangpinrkdmxid":shangpinrkdmxid},
			success:function(result) {
				if(result.succsess == true){
					 notifySuccess("删除成功"); 
					 $('#tr_'+shangpinrkdmxid).remove();  
					 $('#mxformSave')[0].reset();
					 shangpinrkdj.getShangpinCount(shangpinrkdid);
				}
			}
	   });
	},
	//时间插件
	myDateForRuku: function (firstDate) {
		var dbkaishisj;
		var dbjieshusj;
	 	$.ajax({
			type: "post",
			url: path + "/base/getShujukuTime",
			async: false,
			success: function(data) {
			dbkaishisj=data.dbMonthFirstDay;
			dbjieshusj=data.dbCurrentDate;
			}
		});
		getShujukuTime(dbjieshusj); 
		var yearNow = dbjieshusj.substring(0,4);
		var yearAfter2 = Number(yearNow)+2;
		var dbshijianAfter =  dbjieshusj.replace(yearNow,yearAfter2);
	    $(firstDate).datetimepicker({
	   	    format: "L",
	        allowInputToggle: true,
	    	showTodayButton: true,
	    	});
	    $(firstDate).on("dp.change", function (e) {
			   $(firstDate).data("DateTimePicker").minDate(dbjieshusj);
			});
	},
	getShangpinCount(shangpinrkdid){//获取品类、进货总价、处方总价
		$.ajax({
			url:shangpinrkdj.url.getShangpinCountURL(),
			type:'post',
			data:{"shangpinrkdid":shangpinrkdid},
			success:function(result) {
				console.log(result)
				if(result.succsess == true){
					$('#pinleislsp').text(result.data.pinleisl);
					$('#jinsuozjsp').text(result.data.jinhuozj+"元");
					$('#chufangzjsp').text(result.data.chufangzj+"元");
				}
			}
		});
	},
}